import pandas

from conf.environment_config import *


def get_excel_data(xlsx_name,sheet_name):
    """输入.xlsx，返回数据列表"""

    excel_data_list = []

    pd = pandas.read_excel("./data/" + xlsx_name, sheet_name)
    for hang, data in pd.iterrows():
        data_dict = data.to_dict()
        excel_data_list.append(data_dict)

    #[{},{}]
    return excel_data_list


def excel_to_req(excel_dict):
    """输入用例，返回请求参数"""
    # 开始组装请求参数
    req = {
        "method": excel_dict['请求方式'],
        "url": API_SERVER_DOCKER + excel_dict['URL'],
        "params": eval(excel_dict['post参数']) if pandas.notna(excel_dict['post参数']) else None,
        "data": eval(excel_dict['data参数']) if pandas.notna(excel_dict['data参数']) else None,
        "json": eval(excel_dict['json参数']) if pandas.notna(excel_dict['json参数']) else None,
        "headers": eval(excel_dict['请求头']) if pandas.notna(excel_dict['请求头']) else None
    }

    return req


def excel_to_assert(excel_dict):
    """输入用例，返回断言内容"""

    ass = eval(excel_dict["json断言"]) if pandas.notna(excel_dict["json断言"]) else None

    return ass

def excel_to_export(excel_dict):
    """输入用例，返回提取内容"""
    exp = eval(excel_dict["响应提取"]) if pandas.notna(excel_dict["响应提取"]) else None

    return exp